//
//  DDInterviewReceiveCell.m
//  DingDongZP
//
//  Created by 杨政涛 on 16/10/31.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

#import "DDInterviewReceiveCell.h"
#import "DDInterviewMessage.h"

@interface DDInterviewReceiveCell ()

@property (nonatomic, strong) UILabel *interviewType;

@property (nonatomic, strong) UILabel *interviewTime;

@end

@implementation DDInterviewReceiveCell

{
    UIView *inner;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self.messageTimeLabel removeFromSuperview];
        
        inner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 120)];
        inner.backgroundColor = [UIColor whiteColor];
        inner.layer.masksToBounds = YES;
        inner.layer.cornerRadius = 10.0;
        [self.messageContentView addSubview:inner];
        
        self.interviewType = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, CGRectGetWidth(inner.bounds)-30, 30)];
        self.interviewType.font = [UIFont systemFontOfSize:16];
        self.interviewType.textColor = COLOR_FONT_BLACK;
        [inner addSubview:self.interviewType];
        
        self.interviewTime = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.interviewType.frame),CGRectGetMaxY(self.interviewType.frame), CGRectGetWidth(self.interviewType.frame), CGRectGetHeight(self.interviewType.frame))];
        self.interviewTime.font = [UIFont systemFontOfSize:16];
        self.interviewTime.textColor = COLOR_FONT_BLACK;
        [inner addSubview:self.interviewTime];
        
        UIView *sep1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.interviewTime.frame)+5, 250, 0.5)];
        sep1.backgroundColor = [UIColor lightGrayColor];
        [inner addSubview:sep1];
        
        UIView *sep2 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetWidth(inner.bounds)/2,CGRectGetMaxY(sep1.frame), 0.5, 45)];
        sep2.backgroundColor = [UIColor lightGrayColor];
        [inner addSubview:sep2];
        
        UIButton *refuse = [UIButton setDetailsBtn:@"取消" picName:nil btnBackColor:nil titleColor:[UIColor colorWithRed:1.000 green:0.255 blue:0.255 alpha:1.000]];
        refuse.tag = 10;
        refuse.frame = CGRectMake(0,CGRectGetMaxY(sep1.frame), CGRectGetWidth(inner.bounds)/2, 45);
        [inner addSubview:refuse];
        [refuse addTarget:self action:@selector(refuseInterview:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *accept = [UIButton setDetailsBtn:@"确定" picName:nil btnBackColor:nil titleColor:[UIColor colorWithRed:0.188 green:0.682 blue:0.678 alpha:1.000]];
        accept.tag = 11;
        accept.frame = CGRectMake(CGRectGetWidth(inner.bounds)/2, CGRectGetMaxY(sep1.frame),CGRectGetWidth(inner.bounds)/2, 45);
        [inner addSubview:accept];
        [accept addTarget:self action:@selector(acceptInterview:) forControlEvents:UIControlEventTouchUpInside];

        
    }
    return self;
}

- (void)setDataModel:(RCMessageModel *)model
{
    [super setDataModel:model];
    
    DDInterviewMessage *message = (DDInterviewMessage *)model.content;
    
    NSUserDefaults *hadSendInterview = [NSUserDefaults standardUserDefaults];
    
    if (message.sendTime) {
        
        if ([hadSendInterview boolForKey:message.sendTime] == YES) {
            for (int i = 10; i<12; i++) {
                UIButton *clickButton = (UIButton *)[inner viewWithTag:i];
                [clickButton setTitleColor:COLOR_FONT_LIGHT_GRAY forState:UIControlStateNormal];
                [clickButton setUserInteractionEnabled:NO];
            }
        }else{
            
            UIButton *refuse = (UIButton *)[inner viewWithTag:10];
            [refuse setTitleColor:[UIColor colorWithRed:1.000 green:0.255 blue:0.255 alpha:1.000] forState:UIControlStateNormal];
            [refuse setUserInteractionEnabled:YES];
            
            UIButton *accept = (UIButton *)[inner viewWithTag:11];
            [accept setTitleColor:[UIColor colorWithRed:0.188 green:0.682 blue:0.678 alpha:1.000] forState:UIControlStateNormal];
            [accept setUserInteractionEnabled:YES];
        }
        
    }else{
        
          UIButton *refuse = (UIButton *)[inner viewWithTag:10];
          [refuse setTitleColor:[UIColor colorWithRed:1.000 green:0.255 blue:0.255 alpha:1.000] forState:UIControlStateNormal];
          [refuse setUserInteractionEnabled:YES];
        
          UIButton *accept = (UIButton *)[inner viewWithTag:11];
          [accept setTitleColor:[UIColor colorWithRed:0.188 green:0.682 blue:0.678 alpha:1.000] forState:UIControlStateNormal];
          [accept setUserInteractionEnabled:YES];
    }
    
    
    NSString *interviewType;
    if (message.interviewType == 0) {
        
        interviewType = @"现场面试";
    }
    if (message.interviewType == 1) {
        
        interviewType = @"在线面试";
    }
    
    self.interviewType.text = [NSString stringWithFormat:@"面试类型 : %@",interviewType];
    self.interviewTime.text = [NSString stringWithFormat:@"面试时间 : %@",message.interviewTime];
}

- (void)refuseInterview:(id)sender {
    
    if (self.requestInterviewDelegate) {
        
        DDInterviewMessage *repmodel = (DDInterviewMessage *)self.model.content;
        [self.requestInterviewDelegate dealWithRequestInterview:repmodel accept:NO];
        [self didnotClick];
    }
}

- (void)acceptInterview:(id)sender {
    
    if (self.requestInterviewDelegate) {
        
        DDInterviewMessage *repmodel = (DDInterviewMessage *)self.model.content;
        [self.requestInterviewDelegate dealWithRequestInterview:repmodel accept:YES];
        [self didnotClick];

    }
}

// 点击后 两个按钮变灰色，且均不可点击
- (void)didnotClick
{
    for (int i = 10; i<12; i++) {
        UIButton *clickButton = (UIButton *)[inner viewWithTag:i];
        [clickButton setTitleColor:COLOR_FONT_LIGHT_GRAY forState:UIControlStateNormal];
        [clickButton setUserInteractionEnabled:NO];
    }
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
@end
